import {_decorator, Component, Node, Label} from 'cc';
import {GameController} from "db://assets/scripts/hitBird/GameController";

const {ccclass, property} = _decorator;

@ccclass('ScoreController')
export class ScoreController extends Component {
    /**
     * 分数
     */
    score: number = 0;
    /**
     * 游戏控制器
     */
    @property(GameController)
    gameController: GameController = null;

    start() {

    }

    update(deltaTime: number) {

    }

    /**
     * 加分
     */
    add(score: number) {
        // 加分
        this.score += score;
        // 改变分数
        this.node.getComponent(Label).string = this.score.toString();
        // 当游戏分数大于 100 分时
        if (this.score > 100){
            // 游戏结束
            this.gameController.gameOver();
        }
    }
}

